import { JXDef } from "../../../conventions/JXCommon";
import { OBJECT_COPY, PRIORITY_VIEW } from "../../../Core/CoreDefine";
import GPage from "../../../Core/GView/GPage";
import MathEx from "../../../Core/Math/MathEx";
import ShaderUtil from "../../../Shaders/Manager/ShaderUtil";
import { DETAILSBTN, ITEM_DETAIL_FLAG, PointInfo, RedpointEffect, RPointMask, SELLSTORE, SQUAD_BUTTON, STOREBTNTYPE, STOREBUYTYPE } from "../../Common/Define";
import { LCoin } from "../../Common/Language";
import { VIEW_ID } from "../../Common/UI";
import { Res } from "../../Common/UIResources";
import { JXLocales } from "../../Common/Zh";
import { REquireItem } from "../../Data/RunTime/RunRaw/RItemAttach";
import RJXItem from "../../Data/RunTime/RunRaw/RJXItem";
import GameMgr from "../../Logic/GameMgr";
import JXItem from "../Common/JXItem";
import { GCtrl } from './../../../Core/GCtrl';
import { CMsg, CURRENCY, ITEM_TYPE } from './../../Common/Define';
import StoreEquipItem from "./StoreEquipItem";

const { ccclass, property, menu, executeInEditMode } = cc._decorator;
@ccclass @menu('View/Store/StoreCtrl')

export default class StoreCtrl extends GPage {

    @property({
        type: cc.Node,
        tooltip: "4个固定装备位置"
    })
    storeItem: cc.Node[] = [];


    @property({
        type: cc.Label,
        tooltip: "4个动态渲染文案"
    })
    storeSell: cc.Label[] = [];

    @property({
        type: cc.Sprite,
        tooltip: "4个动态渲染图片"
    })
    storeImg: cc.Sprite[] = [];

    @property({
        type: cc.Label,
        tooltip: "6个抽奖宝箱渲染文案"
    })
    boxLab: cc.Label[] = [];

    @property({
        type: cc.Sprite,
        tooltip: "6个抽奖宝箱渲染图片"
    })
    boxImg: cc.Sprite[] = [];


    @property({
        type: cc.Label,
        tooltip: "3个宝箱渲染文案"
    })
    boxDraw: cc.Label[] = [];

    @property({
        type: cc.Node,
        tooltip: "宝库content"
    })
    content: cc.Node = null;

    /**6个宝箱购买按钮 */
    private buyBtn: DrawCurrencyInfo[] = [];
    /**装备数据 */
    private _equipData: SEquipDataRaw[] = null;
    /**职业商品按钮选项索引 */
    private _curEquipIndex: number = 1;
    /**当前对应职业装备 */
    private _curOnceEquip: SEquipDataRaw[] = null;
    /**当前职业最大等级 */
    private heroLv: number = 1;
    /**购买方式索引 */
    private buyArr: any[] = [];
    private _arr = [];
    private _bool = false;
    private _allGoodsPos: Array<Array<number>> = [];
    onGLoad() {
        this.node.setContentSize(cc.winSize);
        GCtrl.ES.on(CMsg.client.bag.onCurrencyChange, this, this.setRedPoint.bind(this), PRIORITY_VIEW)
        this._equipData = GameMgr.equipData.data.values();
        this.changeNum();
        this.goodsPos();
        this.init();
    }

    /**点击职业商品按钮选项 */
    btnOnce(CustomEventData) {
        this._curEquipIndex = Number(CustomEventData.node._name);
        this._curOnceEquip = null;
        for (let i = 0; i < this.storeItem.length; i++) {
            this.storeItem[i].getChildByName('sell').getComponent(cc.Button).interactable = true;
            ShaderUtil.normal(this.storeItem[i].getChildByName('sell'), true);

        }
        this.init();
    }

    /**选择装备等级 */
    private section(lv) {
        let maxLv = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.lvCap);
        let index = (Number(maxLv) / 10);
        let bool = false;
        let select = 1;
        for (let i = 0; i < index; i++) {
            if (!bool) {
                if (lv <= 10) {
                    bool = true;
                    // console.log('选择装备等级1', i);
                    select = i;

                } else if (lv >= (i + 1) * 10 && lv < (i + 2) * 10) {
                    bool = true;
                    // console.log('选择装备等级2', i + 1);
                    select = i + 1;

                } else if (lv >= index * 10) {
                    bool = true;
                    // console.log('选择装备等级3', index);
                    select = index;

                }
            }
        }
        return select
    }


    /**生成所有货架位置 */
    protected goodsPos() {
        for (let i = 0; i < 5; i++) {
            for (let j = 0; j < 4; j++) {
                let arr = [i, j];
                this._allGoodsPos.push(arr);
            }
        }

    }


    /**
     * 先取到所有装备 
     * 在取到当前职业的装备 
     * 在取到当前职业最高等级取对应等级装备
     * 没有英雄就取初始等级的等级装备 
     * 在随机初始4个按钮 
     * 取到对应装备的交易方式 
     */
    protected init() {
        this.buyArr = [];
        this.heroLv = GameMgr.rHeroData.curHeroTypeMaxLv(this._curEquipIndex);
        // console.log('当前职业最大等级', this.heroLv);
        let select = this.section(this.heroLv);

        //宝箱说明
        let boxDraw1: string = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.boxDraw1);
        let boxDraw2: string = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.boxDraw2);
        let boxDraw3: string = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.boxDraw3);

        this.boxDraw[0].string = boxDraw1;
        this.boxDraw[1].string = boxDraw2;
        this.boxDraw[2].string = boxDraw3;

        let labArr = [];

        //售卖类型
        let sell: [] = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.sell);
        let isUseFree = GameMgr.userMgr.checkCanBuyFree();
        //拷贝一份交易类型数据
        let sellArr = sell;
        //每个按钮每次刷新不一样的交易方式
        var count;
        //取到对应 职业类型，等级限制 ,全局品质限制的所有装备
        this._curOnceEquip = GameMgr.equipData.getEquipByEquip(this._curEquipIndex, select * 10);
        // console.log('this._curOnceEquip', this._curOnceEquip, select);

        this.assetImpl.prefab(Res.prefab.vw.store.storeEquipItem, (prefab: cc.Prefab) => {
            var STOREGOODS: STOREGOODS = {
                pillIndex: null,
                chipIndex: null,
                pillInfo: null,
                chipInfo: null,
            }
            var allPos: Array<Array<number>> = null;
            allPos = OBJECT_COPY(this._allGoodsPos);
            let posIndex = MathEx.random(0, allPos.length - 1);
            //突破丹出现一个
            STOREGOODS.pillIndex = [allPos[posIndex]];
            allPos.splice(posIndex, 1);
            let lvData = GameMgr.lvData.getRaw<SLvDataRaw>(this.heroLv);
            let pillInfo = lvData.quality + 1;
            if (pillInfo >= 6) {
                pillInfo = 6;
            }
            STOREGOODS.pillInfo = pillInfo;

            //英雄碎片
            //英雄碎片数量
            let chipNum: number = MathEx.random(1, 3);
            let chipArrs = [];
            let chipIdArr = [];
            for (let i = 0; i < chipNum; i++) {
                let allHero = GameMgr.rHeroData.getHaveHeros(SQUAD_BUTTON.ALL);
                let num = allHero.have.length + allHero.notHave.length;
                let heroChipId: number = MathEx.random(1, num);//英雄碎片id随机
                chipIdArr.push(heroChipId);
                let posIndex = MathEx.random(0, allPos.length - 1);
                chipArrs.push(allPos[posIndex]);
                allPos.splice(posIndex, 1);
            }
            STOREGOODS.chipIndex = chipArrs;
            STOREGOODS.chipInfo = chipIdArr;

            if (this.content.children.length >= 5) {
                for (let i = 0; i < 5; i++) {
                    let comp = this.content.children[i].getComponent(StoreEquipItem)
                    comp.init(this._curOnceEquip, this._curEquipIndex, STOREGOODS, i);
                }
            } else {
                for (let i = 0; i < 5; i++) {
                    let comp = this.assetImpl.addGChild<StoreEquipItem>(prefab);
                    comp.node.parent = this.content;
                    comp.init(this._curOnceEquip, this._curEquipIndex, STOREGOODS, i);
                }
            }

        })
        return
        //刷新货架上每个位置的的装备信息以及交易方式
        for (let i = 0; i < this.storeItem.length; i++) {
            let num = MathEx.random(0, this._curOnceEquip.length - 1);//随机一件装备
            let sellNum = MathEx.random(0, sellArr.length - 1);//随机一件装备
            for (let j = 0; j < sellArr.length; j++) {
                if (j == sellNum) {
                    count = sellArr[j];
                    sellArr.splice(j, 1);
                }
            }
            //是否可以使用免费次数以及交易方式原本为金币交易类型 修改为免费
            if (!isUseFree && count == 0) {
                count = 1;
            }
            if (isUseFree && count == 1) {
                count = 0;
                isUseFree = false;
            }

            this.assetImpl.prefab(Res.prefab.item.jxItem, (prefab: cc.Prefab) => {
                let child = this.storeItem[i].getChildByName('JXItem');
                if (child) {
                    let equipValue = [this._curOnceEquip[num].id, ITEM_TYPE.EQUIPDATA, 1];
                    let equip = new RJXItem(equipValue);

                    let jumpEquip: jumpEquip = {
                        insId: '',
                        bool: false,
                        site: 0
                    }

                    child.getComponent(JXItem).setView(equip, ITEM_DETAIL_FLAG.NO_BG | ITEM_DETAIL_FLAG.NO_NUM | ITEM_DETAIL_FLAG.SCALEICON, () => {
                        let arr = ['0', this._curOnceEquip[num].id, 0]
                        let equip = new REquireItem(arr);
                        GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.EquipDetailsCtrl, equip, jumpEquip, null, DETAILSBTN.DETAILSBTN2);
                    });
                } else {
                    let comp = this.assetImpl.addGChild<JXItem>(prefab);
                    let equipValue = [this._curOnceEquip[num].id, ITEM_TYPE.EQUIPDATA, 1];
                    let equip = new RJXItem(equipValue);
                    comp.node.parent = this.storeItem[i];
                    comp.node.setPosition(0, 0);

                    let jumpEquip: jumpEquip = {
                        insId: '',
                        bool: false,
                        site: 0
                    }

                    let arr = ['0', this._curOnceEquip[num].id, 0]
                    let rEquireItem = new REquireItem(arr);
                    comp.setView(equip, ITEM_DETAIL_FLAG.NO_BG | ITEM_DETAIL_FLAG.NO_NUM | ITEM_DETAIL_FLAG.SCALEICON, () => {
                        GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.EquipDetailsCtrl, rEquireItem, jumpEquip, null, DETAILSBTN.DETAILSBTN2);
                    });
                }
            })
            this.storeItem[i].getChildByName('lab').getComponent(cc.Label).string = this._curOnceEquip[num].name;
            let obj: equipSell = {
                sell: count,
                sellData: this._curOnceEquip[num]
            }
            this.buyArr.push(obj);
            this.assetImpl.spriteAtlasFrame(this.storeItem[i].getComponent(cc.Sprite), Res.texture.views.common, "equip_" + this._curOnceEquip[num].trait);
            // console.log("asdsadsads", i);

            labArr.push(num);

        }
        // console.log('this.buyArr', this.buyArr);
        labArr.forEach((v, i) => {
            // console.log('第几个货架位置', i);
            this.initBtnLab(i, v);
            this._bool = false;
        })


        this.setRedPoint();
    }

    protected setRedPoint() {
        for (let i = 0; i < this.buyArr.length; i++) {
            GameMgr.redMgr.setRPointView(this.storeItem[i], this.storeItem[i], this.buyArr[i].sell == SELLSTORE.FREE, RedpointEffect.REDPOINT)
        }
        for (let i = 0; i < this.buyBtn.length; i++) {
            let buyInfo: DrawCurrencyInfo = this.buyBtn[i];
            if (buyInfo.type === STOREBUYTYPE.VIDEO) continue;
            let coin = new RJXItem([buyInfo.id, ITEM_TYPE.CURRENCY, buyInfo.num])
            let result = GameMgr.itemMgr.testCost(coin, 1, false)
            let target = this.boxImg[i].node.parent;
            GameMgr.redMgr.setRPointView(target, target, result.enough, RedpointEffect.REDPOINT);
        }
        GameMgr.redMgr.sendValuesSettingMsgs([RPointMask.RPM_Box_Baiyin, RPointMask.RPM_Box_Huangjin, RPointMask.RPM_Box_Zhuanshu], false);
    }
    /**
     * @param index 第几个货架位置
     * @param num 第几件装备信息
     */
    protected initBtnLab(index: number, num: number) {
        return
        // console.log("this.buyArr", this.buyArr[index], this._curOnceEquip[num].sellRecycle[index]);

        switch (this.buyArr[index].sell) {
            case SELLSTORE.COIN:
                {
                    this.storeSell[index].node.x = 47;
                    // this.storeSell[index].string = LCoin(this._curOnceEquip[num].sellRecycle[index - 1]) + '';
                    this.storeSell[index].string = LCoin(this.buyArr[index].sellData.sellRecycle[SELLSTORE.COIN - 1]);
                    this.assetImpl.spriteAtlasFrame(this.storeImg[index], Res.texture.views.icon, 'icon_101');
                    this.storeImg[index].node.setScale(0.4);
                }
                break;
            case SELLSTORE.DIAMONDS:
                {
                    this.storeSell[index].node.x = 47;
                    // this.storeSell[index].string = LCoin(this._curOnceEquip[num].sellRecycle[index - 1]) + '';
                    this.storeSell[index].string = LCoin(this.buyArr[index].sellData.sellRecycle[SELLSTORE.DIAMONDS - 1]);
                    this.assetImpl.spriteAtlasFrame(this.storeImg[index], Res.texture.views.icon, 'icon_100');
                    console.log('DIAMONDS', index, this._curOnceEquip[num].sellRecycle[SELLSTORE.DIAMONDS - 1]);
                    this.storeImg[index].node.setScale(0.4);
                }
                break;
            case SELLSTORE.VIDEO:
                {
                    this.storeSell[index].node.x = 47;
                    this.storeSell[index].string = '领取';//'视频' + this._curOnceEquip[num].sellRecycle[SELLSTORE.VIDEO - 1] + '';
                    this.storeImg[index].spriteFrame = null;
                    this.assetImpl.spriteAtlasFrame(this.storeImg[index], Res.texture.views.icon, 'icon_video');
                    this.storeImg[index].node.setScale(1);
                }
                break;
            case SELLSTORE.FREE:
                {
                    this.storeSell[index].node.x = 33;
                    this.storeSell[index].string = '免费';
                    this.storeImg[index].spriteFrame = null;
                }
                break;
            default:
                break;
        }
        // for (let i = 0; i < this.buyArr.length; i++) {

        //     console.log('第几个货架', this.buyArr[i].sell);
        //     if (this.buyArr[i].sell == SELLSTORE.COIN) {

        //         this.storeSell[i].node.x = 47;
        //         this.storeSell[i].string = LCoin(this._curOnceEquip[num].sellRecycle[SELLSTORE.COIN - 1]);
        //         console.log("COIN", index, this._curOnceEquip[num].sellRecycle[SELLSTORE.COIN - 1]);
        //         this.assetImpl.spriteAtlasFrame(this.storeImg[i], Res.texture.views.icon, 'icon_101');
        //         this.storeImg[i].node.setScale(0.4);
        //     } else if (this.buyArr[i].sell == SELLSTORE.DIAMONDS) {

        //         this.storeSell[i].node.x = 47;
        //         this.storeSell[i].string = LCoin(this._curOnceEquip[num].sellRecycle[SELLSTORE.DIAMONDS - 1]) + '';
        //         this.assetImpl.spriteAtlasFrame(this.storeImg[i], Res.texture.views.icon, 'icon_100');
        //         console.log('DIAMONDS', index, this._curOnceEquip[num].sellRecycle[SELLSTORE.DIAMONDS - 1]);
        //         this.storeImg[i].node.setScale(0.4);
        //     } else if (this.buyArr[i].sell == SELLSTORE.VIDEO) {

        //         this.storeSell[i].node.x = 47;
        //         this.storeSell[i].string = '领取';//'视频' + this._curOnceEquip[num].sellRecycle[SELLSTORE.VIDEO - 1] + '';
        //         this.storeImg[i].spriteFrame = null;
        //         this.assetImpl.spriteAtlasFrame(this.storeImg[i], Res.texture.views.icon, 'icon_video');
        //         this.storeImg[i].node.setScale(1);
        //     } else if (this.buyArr[i].sell == SELLSTORE.FREE) {

        //         this.storeSell[i].node.x = 33;
        //         this.storeSell[i].string = '免费';
        //         this.storeImg[i].spriteFrame = null;
        //     }
        // }
    }

    /**购买商品装备 */
    protected buyClick(CustomEventData, index: number) {
        return
        let bool = false;
        switch (this.buyArr[index].sell) {
            case SELLSTORE.FREE: {
                bool = true;
                this.buyArr[index].sell = SELLSTORE.COIN;
                GameMgr.lUserData.useDayFree();
                this.setRedPoint();
                // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_buy_free })
                if (bool) {
                    this.store(index);
                }
                // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.detailsCtrl, { msg: L(JXLocales.tower.store, this._curEquipIndex) })
                break;
            }

            case SELLSTORE.COIN: {
                let num = this.buyArr[index].sellData.sellRecycle[SELLSTORE.COIN - 1];
                let coin = new RJXItem([CURRENCY.GOLD, ITEM_TYPE.CURRENCY, num])
                let result = GameMgr.itemMgr.testCost(coin, 1, true)
                if (result.enough) {
                    GCtrl.ES.emit(CMsg.client.bag.onBagItemChange, [[CURRENCY.GOLD, ITEM_TYPE.CURRENCY, -num]])
                    bool = true;
                    // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_buy_coin })
                    if (bool) {
                        this.store(index);
                    }
                } else {
                    GameMgr.uiMgr.showToast(result.tip)

                }
                break;
            }
            case SELLSTORE.DIAMONDS: {
                let num = this.buyArr[index].sellData.sellRecycle[SELLSTORE.DIAMONDS - 1];
                let yushi = new RJXItem([CURRENCY.YUSHI, ITEM_TYPE.CURRENCY, num]);
                let result = GameMgr.itemMgr.testCost(yushi, 1, true);
                if (result.enough) {
                    GCtrl.ES.emit(CMsg.client.bag.onBagItemChange, [[CURRENCY.YUSHI, ITEM_TYPE.CURRENCY, -num]])
                    bool = true;
                    // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_buy_diamond })
                    if (bool) {
                        this.store(index);
                    }
                } else {
                    GameMgr.uiMgr.showToast(result.tip)
                }
                break;
            }
            case SELLSTORE.VIDEO: {
                GameMgr.sdkMgr.watchAd(() => {
                    bool = true;
                    // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_buy_video })
                    if (bool) {
                        this.store(index);
                    }
                })
                break;
            }
            default:
                break;
        }

        let name = GameMgr.lUserData.heroType(this._curEquipIndex);
        GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: JXLocales.tower.store + '-' + name })
    }

    /**成功购买装备 */
    protected store(index: number) {
        return
        this.storeItem[index].getChildByName('sell').getComponent(cc.Button).interactable = false;
        ShaderUtil.gray(this.storeItem[index].getChildByName('sell'), true);
        let awardArr: number[][] = [];
        let arr = [];
        arr.push(this.buyArr[index].sellData.id);
        arr.push(SELLSTORE.COIN);
        arr.push(SELLSTORE.COIN);
        awardArr.push(arr);
        GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.rewardCtrl, awardArr);
    }

    //抽奖奖池
    protected luckDraw(boxType: number) {
        return
        let drawData = null;
        drawData = GameMgr.dialData.getDialByType(boxType);
        //抽奖奖池
        let drawList = [];
        let array = [];
        drawData.forEach((value) => {
            let config: DrawConfig = {
                id: value.id,
                type: value.type,
                weight: value.weight,
                award: value.award,
            }
            drawList.push(config);
        })

        for (let i = 0; i < drawList.length; i++) {
            let weight = drawList[i].weight;
            for (let j = 0; j < weight; j++) {
                array.push(i);
            }
        }
        array = MathEx.fisherYatesShuffle(array);
        // console.log(array);
        let index = Math.floor(Math.random() * array.length);
        // console.log(drawList, 'drawList[array[index]', drawList[array[index]]);
        GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.rewardCtrl, drawList[array[index]].award);
        drawList = [];
    }


    /**点击抽奖 */
    protected draw(data, boxType: number) {
        return
        let box = this.buyBtn[data.currentTarget._name];
        if (box.id == STOREBUYTYPE.VIDEO) {
            GameMgr.sdkMgr.watchAd(() => {
                switch (boxType) {
                    case STOREBTNTYPE.boxL:
                    case STOREBTNTYPE.boxR: {
                        GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_open_ybox_video })
                        break;
                    }
                    case STOREBTNTYPE.silverBoxL:
                    case STOREBTNTYPE.silverBoxR: {
                        GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_open_jbox_video })
                        break;
                    }
                    case STOREBTNTYPE.goldBoxR:
                    case STOREBTNTYPE.goldBoxL: {
                        GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_open_zbox_video })
                        break;
                    }
                }
                this.luckDraw(Number(boxType));
            })
        } else {
            let num = box.num;
            let coin = new RJXItem([box.id, ITEM_TYPE.CURRENCY, num])
            let result = GameMgr.itemMgr.testCost(coin, 1, true)
            if (result.enough) {
                GCtrl.ES.emit(CMsg.client.bag.onBagItemChange, [[box.id, ITEM_TYPE.CURRENCY, -num]])
                switch (Number(boxType)) {
                    case STOREBTNTYPE.boxL:
                    case STOREBTNTYPE.boxR: {
                        // let way = box.id === STOREBUYTYPE.COIN ? PointInfo.store_open_ybox_coin : PointInfo.store_open_ybox_diamod;
                        // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: way })
                        GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_open_ybox })
                        break;
                    }
                    case STOREBTNTYPE.silverBoxL:
                    case STOREBTNTYPE.silverBoxR: {
                        // let way = box.id === STOREBUYTYPE.COIN ? PointInfo.store_open_jbox_coin : PointInfo.store_open_jbox_diamod;
                        // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: way })
                        GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_open_jbox })
                        break;
                    }
                    case STOREBTNTYPE.goldBoxR:
                    case STOREBTNTYPE.goldBoxL: {
                        // let way = box.id === STOREBUYTYPE.COIN ? PointInfo.store_open_zbox_coin : PointInfo.store_open_zbox_diamod;
                        // GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: way })

                        GameMgr.sdkMgr.umaSetPoint(JXDef.umaPoint.storeCtrl, { msg: PointInfo.store_open_zbox })
                        break;
                    }
                }
                this.luckDraw(Number(boxType));
            } else {
                GameMgr.uiMgr.showToast(result.tip)
            }
        }
    }

    /**宝箱抽奖货币方式 */
    protected changeNum() {
        return
        let silverBoxOpen: number[] = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.silverBoxOpen);
        let box1 = STOREBTNTYPE.boxL;
        silverBoxOpen.forEach((v, index) => {
            if (v != -1) {
                this.drawType(v, index, box1);
                box1++;
            }
        })

        let GoldBoxOpen: number[] = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.GoldBoxOpen);
        let box2 = STOREBTNTYPE.silverBoxL;
        GoldBoxOpen.forEach((v, index) => {
            if (v != -1) {
                this.drawType(v, index, box2);
                box2++;
            }
        })
        let dearBoxOpen: number[] = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.dearBoxOpen);
        let box3 = STOREBTNTYPE.goldBoxL;
        dearBoxOpen.forEach((v, index) => {
            if (v != -1) {
                this.drawType(v, index, box3);
                box3++;
            }
        })
    }

    protected drawType(v: number, index: number, boxId: number) {
        return
        if (index == STOREBUYTYPE.COIN) {
            let DrawCurrencyInfo: DrawCurrencyInfo = {
                id: CURRENCY.GOLD,
                type: ITEM_TYPE.CURRENCY,
                num: v
            }
            this.assetImpl.spriteAtlasFrame(this.boxImg[boxId], Res.texture.views.icon, 'icon_101');
            this.boxLab[boxId].string = LCoin(v) + '';
            this.boxImg[boxId].node.setScale(0.4);
            this.buyBtn.push(DrawCurrencyInfo);
        } else if (index == STOREBUYTYPE.YUSHI) {
            let DrawCurrencyInfo: DrawCurrencyInfo = {
                id: CURRENCY.YUSHI,
                type: ITEM_TYPE.CURRENCY,
                num: v
            }
            this.assetImpl.spriteAtlasFrame(this.boxImg[boxId], Res.texture.views.icon, 'icon_100');
            this.boxImg[boxId].node.setScale(0.4);
            this.boxLab[boxId].string = LCoin(v) + '';
            this.buyBtn.push(DrawCurrencyInfo);
        } else if (index == STOREBUYTYPE.VIDEO) {
            let DrawCurrencyInfo: DrawCurrencyInfo = {
                id: STOREBUYTYPE.VIDEO,
                type: STOREBUYTYPE.VIDEO,
                num: v
            }
            this.assetImpl.spriteAtlasFrame(this.boxImg[boxId], Res.texture.views.icon, 'icon_video');
            this.boxImg[boxId].node.setScale(1);
            this.boxLab[boxId].string = '领取';
            this.buyBtn.push(DrawCurrencyInfo);
        }
    }

    public close() {
        GameMgr.jumpToMgr.jumpGoTo(VIEW_ID.mainPage);
    }
}